package com.ican.service.rule;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.ican.common.hibernate.Page;
import com.ican.dao.product.LanguageDao;
import com.ican.dao.rule.CategoryRuleDao;
import com.ican.dao.rule.ParseRuleDao;
import com.ican.dao.rule.WebsiteRuleDao;
import com.ican.domain.product.Language;
import com.ican.domain.rule.CategoryRule;
import com.ican.domain.rule.ParseRule;
import com.ican.domain.rule.WebsiteRule;

@Service("ruleConfigService")
public class RuleConfigService {

    private LanguageDao languageDao;
    private WebsiteRuleDao websiteRuleDao;
    private CategoryRuleDao categoryRuleDao;
    private ParseRuleDao parseRuleDao;
    
    //语言相关
    public Language findLanguage(Integer id){
        return languageDao.get(id);
    }
    public Language findLanguageByCode(String code){
        return languageDao.findLanguageByCode(code);
    }
    public List<Language> findLanguage(){
        return languageDao.findLanguage();
    }
    
    //站点相关
    public void addWebsite(WebsiteRule website){
        websiteRuleDao.addWebSite(website);
    }
    public void deleteWebsite(Integer id){
        websiteRuleDao.delete(id);
    }
    public void modifyWebsite(WebsiteRule website){
        websiteRuleDao.modifyWebSite(website);
    }
    public WebsiteRule findWebsite(Integer id){
        return websiteRuleDao.get(id);
    }
    public Page<WebsiteRule> findWebsite(Page<WebsiteRule> page, WebsiteRule website){
        return websiteRuleDao.findAllWebsite(page, website);
    }
    public List<WebsiteRule> findWebsite(WebsiteRule website){
        return websiteRuleDao.findAllWebSite(website);
    }
    public void updateWebsiteScanNum(){
        websiteRuleDao.updateWebsiteScanNum();
    }
    
    //类目相关
    public boolean categoryCodeIsExist(String code){
        return categoryRuleDao.categoryCodeIsExist(code);
    }
    public void addCategory(CategoryRule category){
        categoryRuleDao.addCategory(category);
    }
    public void deleteCategory(Integer id){
        categoryRuleDao.delete(id);
    }
    public void modifyCategory(CategoryRule category){
        categoryRuleDao.modifyCategory(category);
    }
    public CategoryRule findCategory(Integer id){
        return categoryRuleDao.get(id);
    }
    public Page<CategoryRule> findCategory(Page<CategoryRule> page, CategoryRule category){
        return categoryRuleDao.findAllCategory(page, category);
    }
    public List<CategoryRule> findCategory(CategoryRule category){
        return categoryRuleDao.findAllCategory(category);
    }
    public void updateCategoryScanStatus(Integer cateId, Integer scanStatus){
        categoryRuleDao.updateCategoryScanStatus(cateId, scanStatus);
    }
    public void updateCategoryScanStatusAndLastPageUrl(Integer cateId, Integer scanStatus, String lastPageUrl){
        categoryRuleDao.updateCategoryScanStatusAndLastPageUrl(cateId, scanStatus, lastPageUrl);
    }
    public List<Integer> findAllCategoryIdToScan(CategoryRule category){
        return categoryRuleDao.findAllCategoryIdToScan(category);
    }
    
    //规则相关
    public void addRule(ParseRule rule){
        parseRuleDao.addRule(rule);
    }
    public void deleteRule(Integer id){
        parseRuleDao.delete(id);
    }
    public void modifyRule(ParseRule rule){
        parseRuleDao.modifyRule(rule);
    }
    public ParseRule findRule(Integer id){
        return parseRuleDao.get(id);
    }
    public ParseRule findRuleByCategoryId(Integer categoryId){
        return parseRuleDao.findRuleByCategoryId(categoryId);
    }
    public Page<ParseRule> findAllRule(Page<ParseRule> page, ParseRule rule){
        return parseRuleDao.findAllRule(page, rule);
    }
    public List<ParseRule> findAllRule(ParseRule rule){
        return parseRuleDao.findAllRule(rule);
    }
    public List<ParseRule> findAllRule(Integer websiteId, int dateStatus){
        return parseRuleDao.findAllRule(websiteId, dateStatus);
    }

    @Resource
    public void setWebsiteRuleDao(WebsiteRuleDao websiteRuleDao) {
        this.websiteRuleDao = websiteRuleDao;
    }
    @Resource
    public void setCategoryRuleDao(CategoryRuleDao categoryRuleDao) {
        this.categoryRuleDao = categoryRuleDao;
    }
    @Resource
    public void setParseRuleDao(ParseRuleDao parseRuleDao) {
        this.parseRuleDao = parseRuleDao;
    }
    @Resource
    public void setLanguageDao(LanguageDao languageDao) {
        this.languageDao = languageDao;
    }
}
